package com.medvalley.tcm.dao;

import com.medvalley.tcm.domain.YangShengXieZi;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface YangShengXieZiDao extends JpaRepository<YangShengXieZi, Long> {

    Page<YangShengXieZi> findAllByStatus(Pageable pageable, int status);

    @Query(nativeQuery = true, value = " SELECT   * FROM   t_yangsheng_xiezi t1 WHERE t1.id >=  ((SELECT MAX(id)  FROM `t_yangsheng_xiezi` where status =1 ) -  (SELECT  MIN(id)  FROM  t_yangsheng_xiezi where status = 1)) * RAND() +  (SELECT MIN(id) FROM  t_yangsheng_xiezi where status = 1) and status =1 LIMIT :num")
    List<YangShengXieZi> findAllByRand(@Param(value = "num") int num);

    List<YangShengXieZi> findAllByIdIn(List<Long> ids);
}
